package com.vertx.core.http;

import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerOptions;

/**
 * @version v1.0
 * @Description: TODO(一句话描述该类的功能)
 * @Author: TongRui乀
 * @Date: 2021/5/10 6:54 下午
 */
public class HttpService {


    public static void main(String[] args) {
        var options = new HttpServerOptions();

        options.setPort(8080);
        options.setIdleTimeout(1000);
        options.setHost("127.0.0.1");

        var http = Vertx.vertx().createHttpServer();

        http.connectionHandler(connector->{
            System.out.println("http connect success " + connector.localAddress().host());
        });

        http.requestHandler(request->{

            HttpMethod method = request.method();

            System.out.println(method.name());

            System.out.println(request.uri());

            System.out.println(request.path());

            System.out.println(request.query());
            // 普通表单url中的参数
            MultiMap params = request.params();

            request.handler(buffer->{
                System.out.println(buffer.toString());
            });

        });



        http.listen(h->{
            if (h.succeeded()) {
                System.out.println("http server started success");
            }
        });
    }


}
